package com.serviceprovider.business.module.order.model;

//~--- non-JDK imports --------------------------------------------------------

import com.serviceprovider.business.module.order.valueobjects.OrderVO;
import com.serviceprovider.business.module.user.model.impl.User;

//~--- JDK imports ------------------------------------------------------------

import java.util.Date;

/**
 * @author mrduongnv@gmail.com
 */
public class Order {
    private OrderStatus orderStatus = new OrderStatus();
    private Date        createdDate;
    private String      date;
    private Integer     id;
    private String      instructions;
    private Integer     mode;
    private String      name;
    private User        orderAssignedTo;
    private Integer     serviceProviderId;
    private String      tips;

    public Order() {}

    public Order(OrderVO orderVO) {
        this.id           = orderVO.getId();
        this.date         = orderVO.getDate();
        this.name         = orderVO.getName();
        this.mode         = orderVO.getMode();
        this.orderStatus  = new OrderStatus(orderVO.getOrderStatus());
        this.tips         = orderVO.getTips();
        this.instructions = orderVO.getInstructions();
        this.setServiceProviderId(orderVO.getSpId());
        this.createdDate = orderVO.getCreatedDate();
    }

    @Override
    public boolean equals(Object obj) {
        if ((obj == null) ||!(obj instanceof Order)) {
            return false;
        }

        Order   b  = (Order) obj;
        boolean eq = ((id == null) && (b.id == null)) || ((id != null) && id.equals(b.id));

        if (!eq) {
            return false;
        }

        eq = ((name == null) && (b.name == null)) || ((name != null) && name.equals(b.name));

        if (!eq) {
            return false;
        }

        eq = ((date == null) && (b.date == null)) || ((date != null) && date.equals(b.date));

        if (!eq) {
            return false;
        }

        eq = ((orderStatus == null) && (b.orderStatus == null))
             || ((orderStatus != null) && orderStatus.equals(b.orderStatus));

        if (!eq) {
            return false;
        }

        eq = ((serviceProviderId == null) && (b.serviceProviderId == null))
             || ((serviceProviderId != null) && serviceProviderId.equals(b.serviceProviderId));

        if (!eq) {
            return false;
        }

        eq = ((mode == null) && (b.mode == null)) || ((mode != null) && mode.equals(b.mode));

        if (!eq) {
            return false;
        }

        eq = ((instructions == null) && (b.instructions == null))
             || ((instructions != null) && instructions.equals(b.instructions));

        if (!eq) {
            return false;
        }

        eq = ((tips == null) && (b.tips == null)) || ((tips != null) && tips.equals(b.tips));

        if (!eq) {
            return false;
        }

        eq = ((orderAssignedTo == null) && (b.orderAssignedTo == null))
             || ((orderAssignedTo != null) && orderAssignedTo.equals(b.orderAssignedTo));

        if (!eq) {
            return false;
        }

        eq = ((createdDate == null) && (b.createdDate == null))
             || ((createdDate != null) && createdDate.equals(b.createdDate));

        if (!eq) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        int prime  = 31;
        int result = 1;

        result = prime * result + ((id == null)
                                   ? 0
                                   : id.hashCode());
        result = prime * result + ((name == null)
                                   ? 0
                                   : name.hashCode());
        result = prime * result + ((date == null)
                                   ? 0
                                   : date.hashCode());
        result = prime * result + ((orderStatus == null)
                                   ? 0
                                   : orderStatus.hashCode());
        result = prime * result + ((serviceProviderId == null)
                                   ? 0
                                   : serviceProviderId.hashCode());
        result = prime * result + ((mode == null)
                                   ? 0
                                   : mode.hashCode());
        result = prime * result + ((instructions == null)
                                   ? 0
                                   : instructions.hashCode());
        result = prime * result + ((tips == null)
                                   ? 0
                                   : tips.hashCode());
        result = prime * result + ((orderAssignedTo == null)
                                   ? 0
                                   : orderAssignedTo.hashCode());
        result = prime * result + ((createdDate == null)
                                   ? 0
                                   : createdDate.hashCode());

        return result;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getMode() {
        return mode;
    }

    public void setMode(Integer mode) {
        this.mode = mode;
    }

    public String getInstructions() {
        return instructions;
    }

    public void setInstructions(String instructions) {
        this.instructions = instructions;
    }

    public String getTips() {
        return tips;
    }

    public void setTips(String tips) {
        this.tips = tips;
    }

    public String getName() {
        return name;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public void setName(String name) {
        this.name = name;
    }

    public OrderStatus getOrderStatus() {
        return orderStatus;
    }

    public void setOrderStatus(OrderStatus orderStatus) {
        this.orderStatus = orderStatus;
    }

    public User getOrderAssignedTo() {
        return orderAssignedTo;
    }

    public void setOrderAssignedTo(User orderAssignedTo) {
        this.orderAssignedTo = orderAssignedTo;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public Integer getServiceProviderId() {
        return serviceProviderId;
    }

    public void setServiceProviderId(Integer serviceProviderId) {
        this.serviceProviderId = serviceProviderId;
    }
}



